package cn.tedu._06article.base.exception;
import cn.tedu._06article.base.response.StatusCode;
import cn.tedu._06article.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public JsonResult doHandleMethodArgumentNotValidException(MethodArgumentNotValidException ex){
        String date = ex.getFieldError().getDefaultMessage();
        log.debug("MethodArgumentNotValidException:" + date);
        return new JsonResult(StatusCode.VALIDATED_ERROR, date);

    }


}
